/*
 * Copyright (c) 2012 SUBSECRETARIA DEFENSORIA DEL ESPACIO PUBLICO - SDEP.
 * All Rights Reserved.
 * This software is the confidential and proprietary information of SDEP
 * Developed By CONSTULT-SOFT S.A, Development Team 2012.
 *
 */
package co.gov.medellin.sdep.sisdep.regulacion.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.ModuloDiseno;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IModuloDisenoDAOT;
import co.gov.medellin.sdep.sisdep.regulacion.exception.ModuloDisenoException;
import co.gov.medellin.sdep.sisdep.regulacion.exception.ModuloDisenoRuntimeException;
import co.gov.medellin.sdep.sisdep.regulacion.exception.descriptor.ModuloDisenoMessageDescriptor;


/**
 * <p>
 * Implementacion de todos los servicios servicios necesarios para la gestion de los Disenios de Modulos asignados a comercientes en SISDEP.
 * </p>
 * <p>
 * Copyright (c) 2012<BR>
 * Consult-Soft S.A.<BR>
 * Created on: May 09, 2012<BR>
 * 
 * @author atabares
 * </p>
 */
public class ModuloDisenoServiceImpl extends BaseService implements IModuloDisenoService {

	/** Serial key. */
	private static final long serialVersionUID = -393045414912476383L;
	
	/** Interface de acceso a los DAOs de Modulo. */
	private IModuloDisenoDAOT moduloDisenoDAO;

	/** Constructor por defecto. */
	public ModuloDisenoServiceImpl() {
		
	}
	
	/**
	* Obtiene el parametro moduloDisenoDAO.
	* @see ModuloDisenoServiceImpl#moduloDisenoDAO
	*
	* @return El parametro moduloDisenoDAO.
	*/
	public IModuloDisenoDAOT getModuloDisenoDAO() {
		return moduloDisenoDAO;
	}

	/**
	* Asigna el parametro moduloDisenoDAO.
	* @see ModuloDisenoServiceImpl#moduloDisenoDAO
	*
	* @param moduloDisenoDAO valor a asignar al parametro moduloDisenoDAO.
	*/
	public void setModuloDisenoDAO(IModuloDisenoDAOT moduloDisenoDAO) {
		this.moduloDisenoDAO = moduloDisenoDAO;
	}

	
	/* (non-Javadoc)
	 * @see co.gov.medellin.sdep.sisdep.regulacion.service.IModuloDisenoService#insert(co.gov.medellin.sdep.sisdep.model.ModuloDiseno)
	 */
	public void insert(ModuloDiseno modulodiseno) throws ModuloDisenoException {
		try{
			getModuloDisenoDAO().insert(modulodiseno);
		} catch (Exception e) {
			Object [] infoError = {
				modulodiseno.getCodigo()
			};
			
			if (e.getCause().toString().toUpperCase().indexOf("ORA-00001") >= 0) {
				throw new ModuloDisenoException(new ModuloDisenoMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			} else {
				throw new ModuloDisenoException(new ModuloDisenoMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/* (non-Javadoc)
	 * @see co.gov.medellin.sdep.sisdep.regulacion.service.IModuloDisenoService#update(co.gov.medellin.sdep.sisdep.model.ModuloDiseno)
	 */
	public final void update(ModuloDiseno modulodiseno) throws ModuloDisenoException {
		try{
			modulodiseno.setUsuarioModifica(getPrincipalUser());
			modulodiseno.setFechaModifica(new Date());
			getModuloDisenoDAO().update(modulodiseno);
		}catch (Exception e) {
			Object [] infoError = {
				modulodiseno.getCodigo()
			};
			
			if (e.getCause().toString().toUpperCase().indexOf("ORA-00001") >= 0) {
				throw new ModuloDisenoRuntimeException(new ModuloDisenoMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			} else {
				throw new ModuloDisenoRuntimeException(new ModuloDisenoMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/* (non-Javadoc)
	 * @see co.gov.medellin.sdep.sisdep.regulacion.service.IModuloDisenoService#delete(co.gov.medellin.sdep.sisdep.model.ModuloDiseno)
	 */
	public final void delete(ModuloDiseno modulodiseno) throws ModuloDisenoException {
		try {
			modulodiseno.setUsuarioModifica(getPrincipalUser());
			modulodiseno.setFechaModifica(new Date());
			getModuloDisenoDAO().delete(modulodiseno);
		}catch (Exception e) {
			Object [] infoError = {
				modulodiseno.getCodigo()
			};
			throw new ModuloDisenoRuntimeException(new ModuloDisenoMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/* (non-Javadoc)
	 * @see co.gov.medellin.sdep.sisdep.regulacion.service.IModuloDisenoService#load(int, int, co.gov.medellin.sdep.sisdep.model.ModuloDiseno)
	 */
	public final List load(int start,int max, ModuloDiseno modulodiseno) throws ModuloDisenoException {
		try{
			//return getModuloDisenoDAO().getAllModuloDisenoPaginated(start, max, criteria);
			return getModuloDisenoDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ModuloDisenoRuntimeException(new ModuloDisenoMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	/* (non-Javadoc)
	 * @see co.gov.medellin.sdep.sisdep.regulacion.service.IModuloDisenoService#get(long)
	 */
	public final ModuloDiseno get(long id) throws ModuloDisenoException {
		try{
			return getModuloDisenoDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new ModuloDisenoRuntimeException(new ModuloDisenoMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	/* (non-Javadoc)
	 * @see co.gov.medellin.sdep.sisdep.regulacion.service.IModuloDisenoService#getModuloDisenoListByCriteria(co.gov.medellin.sdep.sisdep.model.ModuloDiseno)
	 */
	public List getModuloDisenoListByCriteria(ModuloDiseno moduloDisenoSearch) {
		try{
			return getModuloDisenoDAO().getModuloDisenoListByCriteria(moduloDisenoSearch);
		} catch (Exception e) {
			Object [] infoError = null;
			
			throw new ModuloDisenoRuntimeException(new ModuloDisenoMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

}
